package org.xlp.auto.create;

import org.xlp.auto.create.exception.AutoCreatorDataLoseException;
import org.xlp.utils.XLPStringUtil;

/**
 * Description: Dao java文件自动创建类
 * <br/>date: 2023/11/30 11:05
 *
 * @version 1.0
 * @author: xlp
 */
public class DaoAutoCreator extends AbstractAutoCreator{
    public DaoAutoCreator() {
       initAttrDefaultValue();
    }

    /**
     * 构造函数
     * @param entityName
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public DaoAutoCreator(String entityName) {
        this();
        setEntityName(entityName);
        String subPkgName = Constants.DAO_SUB_PACKAGE_NAME + "." + entityName.toLowerCase();
        setSubPackageName(subPkgName);
    }

    /**
     * 构造函数
     *
     * @param abstractAutoCreator
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public DaoAutoCreator(AbstractAutoCreator abstractAutoCreator) {
        super(abstractAutoCreator);
        initAttrDefaultValue();
        String subPkgName = Constants.DAO_SUB_PACKAGE_NAME + "." + abstractAutoCreator.getEntityName().toLowerCase();
        setSubPackageName(subPkgName);
    }

    /**
     * 设置部分属性的默认值
     */
    private void initAttrDefaultValue(){
        setSubPackageName(Constants.DAO_SUB_PACKAGE_NAME);
        setClassType(ClassType.INTERFACE);
    }

    /**
     * java文件注解类容
     *
     * @return
     */
    @Override
    protected String makeAnnotationContent() {
        return XLPStringUtil.EMPTY;
    }

    /**
     * 获取java文件名称
     *
     * @return
     * @throws AutoCreatorDataLoseException 假如获取失败，则抛出该异常
     */
    @Override
    protected String getFileName() throws AutoCreatorDataLoseException {
        if (XLPStringUtil.isEmpty(getEntityName())){
            throw new AutoCreatorDataLoseException("实体名称未设置。");
        }
        return getEntityName() + "Dao" + Constants.JAVA_FILE_SUFFIX;
    }
}
